package Gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class lyricsS {
	public Display lyricsDisplay;
	private Shell lyricsShell;
	public lyricsS(Shell shell, String lyrics , final Main main){
		this.lyricsDisplay = shell.getDisplay();
		this.lyricsShell = new Shell(lyricsDisplay);
		main.addShell(lyricsShell);
		invokelyricsS(shell, lyrics, lyricsShell, lyricsDisplay, main);
	}
	public static void invokelyricsS(Shell shell, String lyrics, final Shell lyricsShell, Display lyricsDisplay, final Main main){
		GridLayout gl = new GridLayout(1,true);
		lyricsShell.setLayout(gl);
		lyricsShell.setText("Lyrics");
		lyricsShell.setLocation(shell.getLocation().x + 50, shell.getLocation().y + 50);
		
		Label Explain = new Label(lyricsShell, SWT.NONE | SWT.V_SCROLL);
		Explain.setLayoutData(new GridData(GridData.BEGINNING,GridData.CENTER,false,true));
		Explain.setText(lyrics);
		
		final Button cancelBt = new Button(lyricsShell,0);
		cancelBt.setText("Close");
		cancelBt.setLayoutData(new GridData(GridData.FILL,GridData.CENTER,true,true));
		
		Listener listener = new Listener () {
			public void handleEvent (Event e) {
				switch (e.type) {
				case SWT.Close:
					main.removeShell(lyricsShell);
					lyricsShell.dispose();
					break;
				default:
		        }	
		   }
		};
		lyricsShell.addListener (SWT.Close, listener);
		
		cancelBt.addSelectionListener(
				new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						main.removeShell(lyricsShell);
						lyricsShell.dispose();
					}
				}
		);
		
		lyricsShell.pack();
		lyricsShell.open();

		while (!lyricsShell.isDisposed()) {
			if (!lyricsDisplay.readAndDispatch())
				lyricsDisplay.sleep();
		}
	}
}
